﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Collections.Generic;
using NLBS.Data;
using NLBS.Entity;
using NLBS.Framework;
using NLBS.Data.Business;
using System.Text;
using NLBS.Web;
using NLBS.Views;


namespace NLBS.Control
{
    public partial class commentList : BaseUserControl, IArticleCommentView
    {

        #region Presenter
        private ArticleCommentPresenter _presenter;

        public ArticleCommentPresenter Presenter
        {
            get
            {
                if (this._presenter == null)
                    _presenter = new ArticleCommentPresenter();
                this._presenter.View = this;
                return _presenter;
            }
        }

        protected void PresenterInit()
        {
            if (!this.IsPostBack)
            {
                this.Presenter.OnViewInitialized();
            }
            this.Presenter.OnViewLoaded();
        }
        #endregion

        #region IArticleCommentView Members

        private IList<Comment> _commentList;
        public IList<Comment> CommentList
        {
            get
            {
                return _commentList;
            }
            set
            {
                _commentList=value;
                if (_commentList.Count > 0)
                {
                    BindComment();
                }
                else
                {
                    noComment.Text = RenderNoComment();
                }
            }
        }

        public int artID
        {
            get { return RequestWrapper.GetQueryInt("ID"); }
        }

        #endregion

        protected void BindComment()
        {

            comment.DataSource = CommentList;
            comment.DataBind();
        }

        public string RenderNoComment()
        {
            StringBuilder sb = new StringBuilder();
            sb.Append("<div class=\"comment-wrapper\">");
            sb.AppendFormat("<div class=\"no-comment-box\">{0}</div>", lang["no_comment"]);
            sb.Append("</div>");
            return sb.ToString();
        }
    }
}